RegisterKeyMapping('+pd', '切换到PD频道', 'keyboard', "")
RegisterCommand('+pd', function()
    exports['pma-voice']:setRadioChannel(5)
end)
RegisterKeyMapping('+fd', '切换到FD频道', 'keyboard', "")
RegisterCommand('+fd', function()
    exports['pma-voice']:setRadioChannel(6)
end)
RegisterKeyMapping('+swat', '切换到SWAT频道', 'keyboard', "")
RegisterCommand('+swat', function()
    exports['pma-voice']:setRadioChannel(8)
end)
RegisterKeyMapping('+tac1', '切换到TAC1频道', 'keyboard', "")
RegisterCommand('+tac1', function()
    exports['pma-voice']:setRadioChannel(9)
end)
RegisterKeyMapping('+tac2', '切换到TAC2频道', 'keyboard', "")
RegisterCommand('+tac2', function()
    exports['pma-voice']:setRadioChannel(10)
end)
RegisterKeyMapping('+tac3', '切换到TAC3频道', 'keyboard', "")
RegisterCommand('+tac3', function()
    exports['pma-voice']:setRadioChannel(11)
end)
RegisterKeyMapping('+pa', '切换到学院频道', 'keyboard', "")
RegisterCommand('+pa', function()
    exports['pma-voice']:setRadioChannel(7)
end)
RegisterKeyMapping('+ooc', '切换到OOC频道', 'keyboard', "")
RegisterCommand('+ooc', function()
    exports['pma-voice']:setRadioChannel(12)
end)
--------------紧急按钮------
local Panic = {}
Panic.Cooling = 0
RegisterKeyMapping('+panic', '紧急按钮', 'keyboard', "")
RegisterCommand("+panic", function()
    if Panic.Cooling == 0 then
        local Officer = {}
        Officer.Ped = PlayerPedId()
        Officer.Name = GetPlayerName(PlayerId())
        Officer.Coords = GetEntityCoords(Officer.Ped)
        Officer.Location = {}
        Officer.Location.Street, Officer.Location.CrossStreet = GetStreetNameAtCoord(Officer.Coords.x, Officer.Coords.y, Officer.Coords.z)
        Officer.Location.Street = GetStreetNameFromHashKey(Officer.Location.Street)
        if Officer.Location.CrossStreet ~= 0 then
            Officer.Location.CrossStreet = GetStreetNameFromHashKey(Officer.Location.CrossStreet)
            Officer.Location = Officer.Location.Street .. " X " .. Officer.Location.CrossStreet
        else
            Officer.Location = Officer.Location.Street
        end

        TriggerServerEvent("Police-Panic:NewPanic", Officer)

        Panic.Cooling = config.Cooldown
    else
        NewNoti("~r~紧急按钮冷却中.", true)
    end
end)

-- 客户端事件
RegisterNetEvent("Pass-Alarm:Return:NewPanic")
AddEventHandler("Pass-Alarm:Return:NewPanic", function(source, Officer)
    if Officer.Ped == PlayerPedId() then
        SendNUIMessage({
            PayloadType	= {"Panic", "LocalPanic"},
            Payload	= source
        })
    else
        SendNUIMessage({
            PayloadType	= {"Panic", "ExternalPanic"},
            Payload	= source
        })
    end

    -- 向聊天框发送信息
    TriggerEvent("chat:addMessage", {
        color = {255, 0, 0},
        multiline = true,
        args = {config.Sender, config.Message .. " - " .. Officer.Name .. " (" .. source .. ") - " .. Officer.Location}
    })

    Citizen.CreateThread(function()
        local Blip = AddBlipForRadius(Officer.Coords.x, Officer.Coords.y, Officer.Coords.z, 100.0)

        SetBlipRoute(Blip, true)

        Citizen.CreateThread(function()
            while Blip do
                SetBlipRouteColour(Blip, 1)
                Citizen.Wait(150)
                SetBlipRouteColour(Blip, 6)
                Citizen.Wait(150)
                SetBlipRouteColour(Blip, 35)
                Citizen.Wait(150)
                SetBlipRouteColour(Blip, 6)
            end
        end)

        SetBlipAlpha(Blip, 60)
        SetBlipColour(Blip, 1)
        SetBlipFlashes(Blip, true)
        SetBlipFlashInterval(Blip, 200)

        Citizen.Wait(config.BlipTime * 1000)

        RemoveBlip(Blip)
        Blip = nil
    end)
end)
Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)

		if Panic.Cooling ~= 0 then
			Citizen.Wait(1000)
			Panic.Cooling = Panic.Cooling - 1
		end
	end
end)
-----调度提示---
RegisterKeyMapping('+dp', '调度按钮', 'keyboard', config.DPKey)
RegisterCommand('+dp', function()
    TriggerServerEvent("dispatch-Button:Newdispatch", Officer)
end)
RegisterNetEvent("Pass-Alarm:Return:Newdispatch")
AddEventHandler("Pass-Alarm:Return:Newdispatch", function(source, Officer)
        SendNUIMessage({
            PayloadType	= {"Dispatch", "dispatch"},
            Payload	= source
        })
end)